/**
 ******************************************************************************
  * @file    user_diskio_softspi.h
  * @brief   This file contains the common defines and functions prototypes for
  *          the user_diskio_softspi driver implementation
  ******************************************************************************
  * Portions copyright (C) 2014, ChaN, all rights reserved.
  * Portions copyright (C) 2017, kiwih, all rights reserved.
  *
  * This software is a free software and there is NO WARRANTY.
  * No restriction on use. You can use, modify and redistribute it for
  * personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY.
  * Redistributions of source code must retain the above copyright notice.
  *
  ******************************************************************************
  */

#ifndef _USER_DISKIO_SOFTSPI_H
#define _USER_DISKIO_SOFTSPI_H

#include "main.h"
#include "ff.h" //from FatFs middleware library
#include "diskio.h" //from FatFs middleware library

//-----[ MMC/SDC Commands ]-----
#define CMD0     (0x40+0)       /* GO_IDLE_STATE */
#define CMD1     (0x40+1)       /* SEND_OP_COND */
#define CMD8     (0x40+8)       /* SEND_IF_COND */
#define CMD9     (0x40+9)       /* SEND_CSD */
#define CMD10    (0x40+10)      /* SEND_CID */
#define CMD12    (0x40+12)      /* STOP_TRANSMISSION */
#define CMD16    (0x40+16)      /* SET_BLOCKLEN */
#define CMD17    (0x40+17)      /* READ_SINGLE_BLOCK */
#define CMD18    (0x40+18)      /* READ_MULTIPLE_BLOCK */
#define CMD23    (0x40+23)      /* SET_BLOCK_COUNT */
#define CMD24    (0x40+24)      /* WRITE_BLOCK */
#define CMD25    (0x40+25)      /* WRITE_MULTIPLE_BLOCK */
#define CMD41    (0x40+41)      /* SEND_OP_COND (ACMD) */
#define CMD55    (0x40+55)      /* APP_CMD */
#define CMD58    (0x40+58)      /* READ_OCR */

//-----[ MMC Card Types (MMC_GET_TYPE) ]-----
#define CT_MMC    0x01  /* MMC ver 3 */
#define CT_SD1    0x02  /* SD ver 1 */
#define CT_SD2    0x04  /* SD ver 2 */
#define CT_SDC    0x06  /* SD */
#define CT_BLOCK  0x08  /* Block addressing */

//we define these as inline because we don't want them to be actual function calls (they get "called" from the cubemx autogenerated user_diskio file)
//we define them as extern because they are defined in a separate .c file to user_diskio.c (which #includes this .h file)

extern DSTATUS USER_SOFTSPI_initialize (BYTE pdrv);
extern DSTATUS USER_SOFTSPI_status (BYTE pdrv);
extern DRESULT USER_SOFTSPI_read (BYTE pdrv, BYTE *buff, DWORD sector, UINT count);
extern DRESULT USER_SOFTSPI_write (BYTE pdrv, const BYTE *buff, DWORD sector, UINT count);
extern DRESULT USER_SOFTSPI_ioctl (BYTE pdrv, BYTE cmd, void *buff);

#endif
